package main

import (
	"fmt"
	"os"

	"fyne.io/fyne"
	"fyne.io/fyne/app"
	"fyne.io/fyne/container"
	"fyne.io/fyne/layout"
	"fyne.io/fyne/theme"
	"fyne.io/fyne/widget"
	"rt.com/mocktool/gui/view"
)

func init() {
	os.Setenv("FYNE_FONT", "font/DroidSansFallback.ttf")
}

func main() {
	myApp := app.New()
	icon, _ := fyne.LoadResourceFromPath("icons/ic_logo.png")
	myApp.SetIcon(icon)
	myApp.Settings().SetTheme(theme.DarkTheme())
	myWindow := myApp.NewWindow("MockTool控制台")
	myWindow.SetTitle("Mocktool控制台")
	myWindow.SetPadded(false)
	myWindow.SetContent(mainWindow())
	myWindow.Resize(fyne.NewSize(270, 420))
	myWindow.SetMaster()
	myWindow.ShowAndRun()
	tidyUp()
}

func mainWindow() fyne.CanvasObject {
	icStart, _ := fyne.LoadResourceFromPath("icons/ic_start.png")
	cont := fyne.NewContainerWithLayout(
		layout.NewGridWrapLayout(fyne.NewSize(160, 160)),
		view.NewIconView(icStart),
	)
	spacer := layout.NewSpacer()
	spacer.Resize(fyne.NewSize(160, 80))
	content := container.NewVBox(
		container.NewCenter(cont),
		spacer,
		container.NewCenter(widget.NewLabel("启动MockTool服务")),
	)
	return container.NewCenter(content)
}

func tidyUp() {
	fmt.Println("Exited")
}
